package com.maiji.cloud.controller;

import com.maiji.cloud.entities.shopingmall.*;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.ReqMetaData;
import com.maiji.cloud.request.shopingmall.MongoLogFindReqData;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseMetaResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.service.*;
import org.apache.commons.lang.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/maijiSettings/")
public class MaijiSettingsController {

    @Autowired
    private RuleFundIntegralService ruleFundIntegralService;
    @Autowired
    private DiscountCouponService discountCouponService;
    @Autowired
    private TaskService taskService;
    @Autowired
	private CapitalMainService capitalMainService;
    @Autowired
	private ShopingOrderService shopingOrderService;
    @Autowired
	private ShipmentsInfoService shipmentsInfoService;

    /**
     * 获取基金或积分使用规则列表
     * @return
     */
    @PostMapping("findAllRuleFundIntegrals")
    public BaseMetaResDto<List<RuleFundIntegral>> findAllRuleFundIntegrals(@RequestBody BaseDataReqDto<Integer> baseDataReqDto){
        Integer type = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return ruleFundIntegralService.findAllRuleFundIntegrals(type, metaData);
    }

    /**
     * 编辑基金或积分使用规则
     * @return
     */
    @PostMapping("editRuleFundIntegral")
    public BaseResDto editRuleFundIntegral(@RequestBody BaseDataReqDto<RuleFundIntegral_log> baseDataReqDto){
        RuleFundIntegral_log data = baseDataReqDto.getData();
        return ruleFundIntegralService.editRuleFundIntegral(data);
    }

    /**
     * 获取减重分享规则修改记录列表
     * @return
     */
    @PostMapping("findAllRuleFundIntegral_logs")
    public BaseMetaResDto<List<RuleFundIntegral_log>> findAllRuleFundIntegral_logs(@RequestBody BaseDataReqDto<MongoLogFindReqData> baseDataReqDto){
        MongoLogFindReqData data = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return ruleFundIntegralService.findAllRuleFundIntegral_logs(data.getType(), data.getOperationDesc(), data.getUpdateDates(), metaData);
    }

    /**
     * 获取优惠券规则列表
     * @return
     */
    @PostMapping("findAllDiscountCoupons")
    public BaseMetaResDto<List<DiscountCoupon>> findAllDiscountCoupons(@RequestBody BaseDataReqDto<DiscountCoupon> baseDataReqDto){
        DiscountCoupon discountCoupon = baseDataReqDto.getData();
        Boolean amount = BooleanUtils.toBoolean(discountCoupon.getAmount());
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return discountCouponService.findAllDiscountCoupons(discountCoupon.getType(), amount, metaData);
    }

    /**
     * 编辑优惠券使用规则
     * @return
     */
    @PostMapping("editDiscountCoupon")
    public BaseResDto editDiscountCoupon(@RequestBody BaseDataReqDto<DiscountCouponLog> baseDataReqDto){
        DiscountCouponLog data = baseDataReqDto.getData();
        return discountCouponService.editDiscountCoupon(data);
    }

    /**
     * 获取优惠券规则修改记录列表
     * @return
     */
    @PostMapping("findAllDiscountCouponLogs")
    public BaseMetaResDto<List<DiscountCouponLog>> findAllDiscountCouponLogs (@RequestBody BaseDataReqDto<MongoLogFindReqData> baseDataReqDto){
        MongoLogFindReqData data = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return discountCouponService.findAllDiscountCouponLogs(data.getType(), data.getOperationDesc(), data.getUpdateDates(), metaData);
    }

    /**
     * 获取积分分发规则列表
     * @return
     */
    @PostMapping("findAllTasks")
    public BaseMetaResDto<List<TaskEntity>> findAllTasks(@RequestBody BaseDataReqDto baseDataReqDto){
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return taskService.findAllTasks(metaData);
    }

    /**
     * 编辑积分分发规则
     * @return
     */
    @PostMapping("editTask")
    public BaseResDto editTask(@RequestBody BaseDataReqDto<TaskLog> baseDataReqDto){
        TaskLog data = baseDataReqDto.getData();
        return taskService.editTask(data);
    }

    /**
     * 获取积分分发修改记录列表
     * @return
     */
    @PostMapping("findAllTaskLogs")
    public BaseMetaResDto<List<TaskLog>> findAllTaskLogs (@RequestBody BaseDataReqDto<List<Date>> baseDataReqDto){
        List<Date> updateDates = baseDataReqDto.getData();
        ReqMetaData metaData = baseDataReqDto.getMetaData();
        return taskService.findAllTaskLogs (updateDates, metaData);
    }

    /**
     * 配置提现金额
     * @param baseDataReqDto
     * @return
     */
    @PostMapping("editWithdrawalAmountLimitConfig")
    public BaseResDto editWithdrawalAmountLimitConfig(@RequestBody BaseDataReqDto<WithdrawalAmountLimitConfigEntity> baseDataReqDto){
        WithdrawalAmountLimitConfigEntity withdrawalAmountLimitConfig = baseDataReqDto.getData();
        return capitalMainService.editWithdrawalAmountLimitConfig(withdrawalAmountLimitConfig);
    }
    
    /**
     * 获取提现金额限制数据
     */
    @PostMapping("findWithdrawalAmountLimitConfig")
    public BaseDataResDto<WithdrawalAmountLimitConfigEntity> findWithdrawalAmountLimitConfig(@RequestBody BaseDataReqDto<Integer> baseDataReqDto){
        Integer type = baseDataReqDto.getData();
        return capitalMainService.findWithdrawalAmountLimitConfig(type);
    }

    /**
     * 获取提现金额限制数据编辑记录
     */
    @PostMapping("findAllWithdrawalAmountLimitConfigLogs")
    public BaseDataResDto<List<WithdrawalAmountLimitConfigEntity>> findAllWithdrawalAmountLimitConfigLogs(@RequestBody BaseDataReqDto<List<Date>> baseDataReqDto){
        List<Date> updateDates = baseDataReqDto.getData();
        return capitalMainService.findAllWithdrawalAmountLimitConfigLogs(updateDates);
    }

    /**
     * 设置订单自动收货设置
     */
    @PostMapping("findAndSetOrderAutoSet")
    public BaseDataResDto<HashMap> findAndSetOrderAutoSet(@RequestBody BaseDataReqDto<HashMap> baseDataReqDto){
        HashMap data = baseDataReqDto.getData();
        return shopingOrderService.findAndSetOrderAutoSet(data);
    }

    /**
     * 设置打印机型号
     */
    @PostMapping("find_setPrinterModel")
    public BaseDataResDto<HashMap> find_setPrinterModel(@RequestBody BaseDataReqDto<HashMap> baseDataReqDto){
        HashMap data = baseDataReqDto.getData();
        return shipmentsInfoService.find_setPrinterModel(data);
    }



}

